package cn.chencq.moudle.lottery.entity;

import java.sql.Timestamp;
import java.util.Arrays;

public class Lottery {

	/**
	 * 主键ID 是由lotteryId + lotteryType + lotteryDate进行MD5生成的32位摘要
	 */
	private String id;
	/**
	 * 期号
	 */
	private String lotteryId;

	/**
	 * 彩票类型 1: 北京幸运28</br>
	 * 2: 北京PK10</br>
	 * 3: 加拿大28</br>
	 * 4: 幸运飞艇</br>
	 * 5: 重庆时时彩</br>
	 * 6: 三分彩</br>
	 * 
	 */
	private int lotteryType;

	/**
	 * 开奖时间
	 */
	private Timestamp lotteryDate;

	/**
	 * 开奖号码
	 */
	private String lotteryNumbers;

	/**
	 * 开奖内容
	 */
	private String lotteryContent;

	/**
	 * 特殊号码 0 : 正常; 1：和13; 2: 和14; 3:对子; 4:顺子 5: 豹子(三个数字一样)
	 */
	private int special = 0;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLotteryNumbers() {
		return lotteryNumbers;
	}

	public void setLotteryNumbers(String lotteryNumbers) {
		this.lotteryNumbers = lotteryNumbers;
		this.special = checkNum(lotteryNumbers);
	}

	public String getLotteryId() {
		return lotteryId;
	}

	public void setLotteryId(String lotteryId) {
		this.lotteryId = lotteryId;
	}

	public int getLotteryType() {
		return lotteryType;
	}

	public void setLotteryType(int lotteryType) {
		this.lotteryType = lotteryType;
	}

	public Timestamp getLotteryDate() {
		return lotteryDate;
	}

	public void setLotteryDate(Timestamp lotteryDate) {
		this.lotteryDate = lotteryDate;
	}

	public String getLotteryContent() {
		return lotteryContent;
	}

	public void setLotteryContent(String lotteryContent) {
		this.lotteryContent = lotteryContent;
	}

	public int getSpecial() {
		return special;
	}

	public void setSpecial(int special) {
		this.special = special;
	}

	public int checkNum(String lotteryNumbers) {
		try {
			String[] strs = lotteryNumbers.split(",");
			int[] arr = new int[3];
			int total = 0;
			for (int i = 0; i < strs.length; i++) {
				arr[i] = Integer.parseInt(strs[i]);
				total += arr[i];
			}
			if (13 == total) {
				return 1;
			}

			if (14 == total) {
				return 2;
			}

			Arrays.sort(arr);

			if ((arr[0] == arr[1] && arr[1] < arr[2]) || (arr[0] < arr[1] && arr[1] == arr[2])) {// 对子
				return 3;
			}

			if ((arr[1] - arr[0] == 1) && (arr[2] - arr[1] == 1)) {// 顺子
				return 4;
			}

			if ((arr[1] - arr[0] == 0) && (arr[2] - arr[1] == 0)) {// 豹子
				return 5;
			}
		} catch (Exception e) {
		}
		return 0;
	}
}
